<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link href="#springUrl('/static/css/plugins/bootstrap-table/bootstrap-table.min.css')" rel="stylesheet">
    <link href="#springUrl('/static/css/jquery-ui.css')" rel="stylesheet">
    <link href="#springUrl('/static/css/style.css')" rel="stylesheet">
    <link href="#springUrl('/static/css/bootstrap.min.css')" rel="stylesheet">
    <script src="#springUrl('/static/js/jquery-2.1.1.js')"></script>
    <script src="#springUrl('/static/js/plugins/bootstrap-table/bootstrap-table.min.js')"></script>
    <script src="#springUrl('/static/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js')"></script>
    <script src="#springUrl('/static/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js')"></script>
    <script src="#springUrl('/static/plugins/layer-v2.2/layer/layer.js')"></script>
    <script src="#springUrl('/static/js/base_list.js')"></script>
    <script src="#springUrl('/static/js/common.js')"></script>
    <script type="text/javascript">
        var dataUrl = "#springUrl('/operate/hotitem/update.html')";
        var dataColumns = [{
            field: 'itemId',
            title: '商品ID'
        },{
            field: 'itemName',
            title: '商品名称',
            width:'200px'
        }, {
            field: 'evaluateCount',
            title: '点评数量',
            formatter: function (value,row,index) {
                if(value!=null){
                    return value;
                }else{
                    return 0;
                }
            }
        }, {
            field: 'grade',
            title: '评分',
            formatter:function(value,row,index){
                if(value!=null) {
                    return (value / 10).toFixed(1);
                }else{
                    return 0;
                }
            }
        }, {
            field: 'price',
            title: '价格',
            formatter: function (value,row,index) {
                if(value==null){
                    return 0;
                }
                return (value/100).toFixed(2);
            }
        }, {
            field: 'advantage',
            title: '点评优点'
        }, {
            field: 'sessionNo',
            title: '期数'
        },{
            field: 'sortFactor',
            title: '排序因子'
        }, {
            field: 'createDate',
            title: '创建日期',
            formatter:function(value,row,index){
                return formatDateSimple(value);
            }
        },{
            title: '操作',
            formatter: function (value, row, index) {
                var id = row.itemId;
                var advantage = row.advantage;
                return '<a class="btn btn-xs btn-info btn-Adv" onclick="editHotItemAdvantage('+index+')">编辑优点</a> '+
                        '<a class="btn btn-xs btn-info btn-Adv" onclick="setHotItemSort('+index+')">设置排序</a> ';
            }
        }
        ];
        function updateShopHotItem(){
            $('#dataTable').bootstrapTable('refresh',{url:"#springUrl('/operate/hotitem/selectUpdateShopHotItemList')"});
//            $.ajax({
//                type: "POST",
//                url: "#springUrl('/operate/hotitem/selectUpdateShopHotItemList')",
//                dataType: "text",
//                success: function (data) {
//
//                }
//            });
        }
var indexRow;
        function setHotItemSort(index){
            indexRow = index;
            setSort();
        }

        function setSort(){
            var title = "设置排序因子";
            layer.open({
                type: 1,
                title: title,
                shadeClose: false,
                shade: 0.8,
                area: ['500px', '200px'],
                fix: false,
                maxmin: true,
                content: $("#setHotItemSortFactor")
            });
        }

        function setSortFactor(){
            var val = $("#sortFactor").val();
            $("#dataTable").bootstrapTable("updateCell",{index:indexRow,field:"sortFactor",value:val});
            layer.closeAll();
            $("#sortFactor").val("");
        }

var editHotItemLayerIndex=-1;
        var $thisA ;
        function editHotItemAdvantage(index){
            indexRow = index;
            updateBtnAdv();
        }

       /* function update(val){
            var e = e||event1;
            var t = e.target||e.srcElement;
            $thisA = $(t);
            $($thisA.parent().parent().children()[5]).html(val);
        }
        function sortA(val){
            var e = e||event1;
            var t = e.target||e.srcElement;
            $thisA = $(t);
            $($thisA.parent().parent().children()[6]).html(val);
        }*/

        function updateBtnAdv(){
                var title = "编辑商品优点";
                layer.open({
                    type: 1,
                    title: title,
                    shadeClose: false,
                    shade: 0.8,
                    area: ['400px', '200px'],
                    fix: false,
                    maxmin: true,
                    content: $("#editHotItemAdvantage")
                });
        }

        function delHotItem(id,sessionNo){
            layer.confirm('确定删除吗？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.ajax({
                    type: "POST",
                    url: "#springUrl('/operate/hotitem/delShopHotItem')?id=" + id+"&sessionNo="+sessionNo,
                    datatype: "text",
                    success: function (data) {
                        var d = JSON.parse(data);
                        if(d.success && d.data){
                            /*window.parent.location.reload();*/
                             $('#dataTable').bootstrapTable('refresh',{url:dataUrl});
                        }
                        layer.closeAll();
                    }
                });
            }, function () {
                return;
            });
        }

        function editAdvantage(){
            var val = $("#itemAdvantage").val();
            $("#dataTable").bootstrapTable("updateCell",{index:indexRow,field:"advantage",value:val});
            layer.closeAll();
            $("#itemAdvantage").val("");
        }

        function confirmUpdateShopHotItem(){
            var trows = $("#dataTable").bootstrapTable("getData");
            var jsonStr = JSON.stringify(trows);
            console.log(jsonStr);
            $.ajax({
                url:"#springUrl('/operate/hotitem/addShopHotItem')",
                type:"post",
                data:jsonStr,
                contentType:"application/json",
                dataType:"json",
                success:function(dt){
                    if(dt.success &&dt.data){
                        window.parent.location.reload();
                    }
                }
            });
        }

    </script>
</head>
<body class="white-bg" >
<button class="btn btn-primary" onclick="updateShopHotItem()" type="button">
    <i class="fa fa-pencil"></i>更新爆款列表</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button class="btn btn-primary" onclick="confirmUpdateShopHotItem()" type="button">
    <i class="fa fa-pencil"></i>确定添加</button>
<br/>
<div class="row">

    <div class="col-sm-12">
        <table id="dataTable"
        ></table>
    </div>
    <div id="editHotItemAdvantage"  style="display: none">
        <div class="form-group"><label class="col-sm-2 control-label">商品优点:</label>
            <div class="col-sm-10">
                <textarea id="itemAdvantage" class="from-control" name="itemAdvantage" style="width: 300px;height: 100px" ></textarea>
            </div>
        </div>
        <div class="form-group" align="right">
        <button class="btn btn-primary" onclick="editAdvantage()" type="button"><i class="fa fa-pencil"></i>确定</button>
            </div>
    </div>
    <form id="setFactor">
    <div id="setHotItemSortFactor"  style="display: none">
        <div class="form-group"><label class="col-sm-2 control-label">排序:</label>
            <div class="col-sm-10">
                <input id="sortFactor" class="from-control" name="sortFactor"  >
            </div>
        </div>
        <div class="form-group" align="right">
            <div class="col-sm-10">
        <button class="btn btn-primary" onclick="setSortFactor()" type="button"><i class="fa fa-pencil"></i>确定</button>
                </div>
            </div>
    </div>
    </form>
</div>

</body>

</html>
